﻿// 简易矢量图生成模型.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include <iostream>
#include <graphics.h>
#include <conio.h>
#include <vector>
#include <commdlg.h>
#include "CShape.h"
#include"文件管理模块.h"
#include"智能指针.hpp"
#include"界面外观模块.h"
#include"鼠标操作模块.h"
#include"界面逻辑模块.h"

//测试鼠标框选实现
void test01() {//实现三次鼠标框选测试
	initgraph(640, 480);
	IMAGE tmp;
	for(int i = 0; i < 3;)
		if (Getimage(&tmp))
			i++;
	_getch();
	closegraph();
}
//测试智能指针实现
void test02() {
	cout << "智能指针生成" << endl;
	{
		AutoPtr<POINT> titi = new POINT({ 10,20 });
		//cout << titi.m_num << '\t' << *titi.m_num << endl;
		//cout << titi.m_ptr << '\t' << (*titi.m_ptr).x << endl;
		AutoPtr<POINT> riri = titi;
		//cout << titi.m_num << '\t' << *titi.m_num << endl;
		//cout << titi.m_ptr << '\t' << titi->x << endl;
	}
}
//测试读取n个点实现
void test03() {
	initgraph(640, 480);
	int n = 0;
	AutoPtr<POINT> pPoint = getPoints(n);
	cout << n << "个点坐标:" << endl;
	for (int i = 0; i < n; ++i) {
		cout << "第" << i+1 << "个点：" << pPoint[i].x << " " << pPoint[i].y << endl;
	}
	_getch();
	closegraph();
}
//测试各类的功能
void test04() {
	initgraph(640, 480);
	//vector维护智能指针，指针维护CShape类
	vector<AutoPtr<CShape>> All_Graphics;
	vector<AutoPtr<CShape>>::iterator it;
	All_Graphics.reserve(100);
	AutoPtr<CShape> C_Ptr;
	POINT pts[4] = { {0,0},{100,100},{20,20},{100,100} };
	
	C_Ptr = new CStraightline({ 30,25 }, { 80,70 });
	All_Graphics.push_back(C_Ptr);
	
	it = All_Graphics.begin();
	(*it)->draw();
	//(*it)->setPoint(1, pts[2]);
	//(*it)->drawColor();
	cout << (*it)->getLength() << ' ';
	C_Ptr = (*it)->copy();
	cout << (*it)->ifShapeIn(CRectangle({20,20},{100,100})) << ' ';
	cout << (*it)->ifShapeIn(pts[2],pts[3]) << ' ';
	(*it)->move(50, 50);
	(*it)->draw();
	cout << (*it)->getPoint(1).x << ' ' << (*it)->getPoint(1).y;
	
	All_Graphics.push_back(C_Ptr);

	/*
	破案了！迭代器容量改变导致迭代器失效	
	//	//it = All_Graphics.begin();
	//	it = All_Graphics.erase(it);//这句话会报错，越界
	//	All_Graphics.erase(All_Graphics.begin());//这句不会
	*/

	_getch();
	closegraph();
}
//创建动画的鼠标操作测试
void test05() {
	initgraph(640, 480);
	
	setlinecolor(WHITE);
	AutoPtr<CShape> ptr;//智能指针接口，用于管理矢量图
	//
	//OPERATOR = c_Triangle;
	//ptr = createSP.select();
	//_getch();
	//
	//OPERATOR = c_Straight;
	//ptr = createSP.select();
	//_getch();
	//
	//OPERATOR = c_Polygon;
	//ptr = createSP.select();
	//_getch();
	//
	//OPERATOR = c_Rectangle;
	//ptr = createSP.select();
	//_getch();

	//OPERATOR = c_Ellipse;
	//ptr = createSP.select();
	//_getch();

	//OPERATOR = c_Circle;
	//ptr = createSP.select();
	//_getch();
	//
	//OPERATOR = c_Select;
	//ptr = createSP.select();
	//_getch();

	OPERATOR = c_Curve;
	ptr = createSP();
	_getch();

	closegraph();
}
//文件的控制测试操作
void test06() {
	initgraph(640, 480);
	//
	//vector维护智能指针，指针维护CShape类
	vector<AutoPtr<CShape>> All_Graphics;
	All_Graphics.reserve(100);
	vector<AutoPtr<CShape>>::iterator it = All_Graphics.begin();
	AutoPtr<CShape> C_Ptr;
	//
	//另外定义一个vector数组，存储该类的其他信息，如颜色等
	vector<COLORREF> ALL_COLOR;



}
//测试打开文件操作
void test07() {
	//HWND test = initgraph(1024, 1024);

	TCHAR szBuffer[MAX_PATH] = { 0 };
	OPENFILENAME ofn = { 0 };
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = NULL;
	ofn.lpstrFilter = _T("Bin文件(*.bin)\0*.bin\0");//要选择的文件后缀   
	ofn.lpstrInitialDir = _T("C:\\Users\\15091\\Desktop\\VStudio工程文件\\简易矢量图生成模型\\存放矢量图二进制文件");//默认的文件路径   
	ofn.lpstrFile = szBuffer;//存放文件的缓冲区   
	ofn.nMaxFile = sizeof(szBuffer) / sizeof(*szBuffer);
	ofn.nFilterIndex = 0;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER;//标志如果是多选要加上OFN_ALLOWMULTISELECT  
	BOOL bSel = GetOpenFileName(&ofn);

	closegraph();
}
//测试另存件操作
void test() {
	;
}
 


int main()
{
	//Window win(960, 650, EX_SHOWCONSOLE);
	//ManageMent m;
	//m.run();
	//return win.exec();
	
	return 0;
}
